package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjCollection;
import com.koron.css2.newProjectCenter.mapper.PjCollectionMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 工程报装-工程收款-单条数据更新
 *
 * @author 朱超
 * @since 2022-01-19 10:44:39
 */
public class PjCollectionUpdate implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjCollectionMapper pjCollectionMapper = factory.getMapper(PjCollectionMapper.class);

            // 1. 获取实例
            PjCollection pjCollection = JsonUtils.objectToPojo(req.getData(), PjCollection.class);
//            // 2. status=2-已收款
//            pjCollection.setStatus(PjCollectionPaymentStatus.AFTERCOLLECTION.getStatus());
//            // 2.1 paymentDate
//            pjCollection.setPaymentDate(new Date());
            // 3. updateTime,updateAccount,updateName
            pjCollection.setUpdateInfo(userInfo);
            // 4. 更新数据
            pjCollectionMapper.update(pjCollection);
            // 5. 返回结果
            return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "工程收款更新成功", null);
        } catch (Exception e) {
            logger.error("工程收款更新失败：",e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL,"工程收款更新失败",null);
        }
    }
}
